import java.awt.*;
import java.awt.image.*;
public class Level {

	Mario 		mario;
	Map   		map;
	Tile  		mapTiles[];
	final int 	colMax 	 = 24; // Number of columns on the screen
	final int 	rowMax 	 = 24; // Number of rows on the screen
	final int 	xScreen    = 16*colMax;
	final int 	yScreen    = 16*rowMax;
	final int 	xMid       = xScreen / 2;
	final int 	yMid       = yScreen / 2;

	Level(){
		
        mario	 = new Mario();		// Create mario object
        mario.SetPos(xMid, yMid);	// Set initial position
        map      = new Map();
		
	}
	
	
	void DrawScene(Graphics g){
        int marioOffset = 0;
        int marioXpos = mario.GetX();
        
        marioOffset =  marioXpos > xMid ? marioXpos - xMid : 0;  
		
		for( int i = 0; i < mapTiles.length ; i++ ){
					mapTiles[i].DrawImage(g, marioOffset, 0);
		}
		mario.DrawImage(g, marioOffset , 0);
	}
	
	void Jump(){
		mario.Jump();
	}
	void RightStart(){
		mario.RightStart();
	}
	void RightStop(){
		mario.RightStop();
	}
	void LeftStart(){
		mario.LeftStart();
	}
	void LeftStop(){
		mario.LeftStop();
	}

	void Update(int deltaTime){
        int marioOffset = 0;
        int marioXpos = mario.GetX();
        
        marioOffset =  marioXpos > xMid ? marioXpos - xMid : 0;  

		// Update the next positions
		mario.NextPosition( deltaTime ); // 30 milliseconds later

		mapTiles = 	map.GetScreenTiles( marioOffset );
		// Check if there are any collisions
		for( int i = 0; i < mapTiles.length ; i++ ){
					mario.CheckBackGroundCollision(mapTiles[i]);
		}

		mario.CommitPosition();
	}
	
		
}
